
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 2023/05/01
// Design Name:
// Module Name: rbm_top
// Project Name: wujian100
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
// base ahb addr is 0x1000_0000  none offset
//////////////////////////////////////////////////////////////////////////////////

module rbm_top
    (//与允许读写权限从机端口相连的
    input                              rbm_a_clk_i,
    input                              rbm_a_rst_n_i,
    input                 [32 - 1 : 0] rbm_a_haddr_i,
    input                 [4  - 1 : 0] rbm_a_hprot_i,                            //hprot[0]为0，代表是来自tee的访问信号，为1，代表是来自ree的访问信号
    input                 [1  - 1 : 0] rbm_a_hsel_i,
    input                 [3  - 1 : 0] rbm_a_hsize_i,
    input                 [2  - 1 : 0] rbm_a_htrans_i,
    input                 [32 - 1 : 0] rbm_a_hwdata_i,
    input                 [1  - 1 : 0] rbm_a_hwrite_i,
    output                [32 - 1 : 0] rbm_a_hrdata_o,
    output                [1  - 1 : 0] rbm_a_hready_o,
    output                [2  - 1 : 0] rbm_a_hresp_o,
    output                [1  - 1 : 0] rbm_a_r2t_intr_o,
    //与只允许读权限从机端口相连的
    input                              rbm_b_clk_i,
    input                              rbm_b_rst_n_i,
    input                 [32 - 1 : 0] rbm_b_haddr_i,
    input                 [4  - 1 : 0] rbm_b_hprot_i,                            //hprot[0]为0，代表是来自tee的访问信号，为1，代表是来自ree的访问信号
    input                 [1  - 1 : 0] rbm_b_hsel_i,
    input                 [3  - 1 : 0] rbm_b_hsize_i,
    input                 [2  - 1 : 0] rbm_b_htrans_i,
    input                 [32 - 1 : 0] rbm_b_hwdata_i,
    input                 [1  - 1 : 0] rbm_b_hwrite_i,
    output                [32 - 1 : 0] rbm_b_hrdata_o,
    output                [1  - 1 : 0] rbm_b_hready_o,
    output                [2  - 1 : 0] rbm_b_hresp_o,
    output                [1  - 1 : 0] rbm_b_r2t_intr_o
    );
localparam ADDR_W                      = 16+3;                                 //子空间有512k的寻址空间

wire                      [1  - 1 : 0] r2t_a_clk_w;
wire                      [1  - 1 : 0] r2t_a_rst_n_w;
wire                      [1  - 1 : 0] r2t_a_en_box;
wire                      [1  - 1 : 0] r2t_a_write_box;
wire                  [ADDR_W - 1 : 0] r2t_a_addr_w;
wire                      [32 - 1 : 0] r2t_a_wdat_w;
wire                      [1  - 1 : 0] r2t_a_rdy_w;
wire                      [32 - 1 : 0] r2t_a_rdat_w;
wire                      [1  - 1 : 0] r2t_a_intr_w;

wire                      [1  - 1 : 0] r2t_b_clk_w;
wire                      [1  - 1 : 0] r2t_b_rst_n_w;
wire                      [1  - 1 : 0] r2t_b_en_box;
wire                      [1  - 1 : 0] r2t_b_write_box;
wire                  [ADDR_W - 1 : 0] r2t_b_addr_w;
wire                      [32 - 1 : 0] r2t_b_wdat_w;
wire                      [1  - 1 : 0] r2t_b_rdy_w;
wire                      [32 - 1 : 0] r2t_b_rdat_w;
wire                      [1  - 1 : 0] r2t_b_intr_w;

/************************************/
/*例化子模块                         */
/************************************/

rm_ahb_if
   #(
    .ADDR_W                            (ADDR_W                                 ),
    .MODE_SEL                          (1                                      )                   
    )
u1_rm_ahb_if
    (
    .rai_clk_i                         (rbm_a_clk_i                            ),            
    .rai_rst_n_i                       (rbm_a_rst_n_i                          ),              
    .rai_haddr_i                       (rbm_a_haddr_i                          ),              
    .rai_hprot_i                       (rbm_a_hprot_i                          ),              
    .rai_hsel_i                        (rbm_a_hsel_i                           ),             
    .rai_hsize_i                       (rbm_a_hsize_i                          ),              
    .rai_htrans_i                      (rbm_a_htrans_i                         ),               
    .rai_hwdata_i                      (rbm_a_hwdata_i                         ),               
    .rai_hwrite_i                      (rbm_a_hwrite_i                         ),               
    .rai_hrdata_o                      (rbm_a_hrdata_o                         ),               
    .rai_hready_o                      (rbm_a_hready_o                         ),               
    .rai_hresp_o                       (rbm_a_hresp_o                          ),              
    .rai_r2t_intr_o                    (rbm_a_r2t_intr_o                       ),        

    .r2t_clk_w                         (r2t_a_clk_w                            ),                  
    .r2t_rst_n_w                       (r2t_a_rst_n_w                          ),                    
    .en_box                            (r2t_a_en_box                           ),                   
    .write_box                         (r2t_a_write_box                        ),                   
    .r2t_addr_w                        (r2t_a_addr_w                           ),                   
    .r2t_wdat_w                        (r2t_a_wdat_w                           ),                   
    .r2t_rdy_w                         (1'b1                                   ),                  
    .r2t_rdat_w                        (r2t_a_rdat_w                           ),                   
    .r2t_intr_w                        (1'b0                                   )                   
    );

rm_ahb_if
   #(
    .ADDR_W                            (ADDR_W                                 ),
    .MODE_SEL                          (2                                      )                     
    )
u2_rm_ahb_if
    (
    .rai_clk_i                         (rbm_b_clk_i                            ),            
    .rai_rst_n_i                       (rbm_b_rst_n_i                          ),              
    .rai_haddr_i                       (rbm_b_haddr_i                          ),              
    .rai_hprot_i                       (rbm_b_hprot_i                          ),              
    .rai_hsel_i                        (rbm_b_hsel_i                           ),             
    .rai_hsize_i                       (rbm_b_hsize_i                          ),              
    .rai_htrans_i                      (rbm_b_htrans_i                         ),               
    .rai_hwdata_i                      (rbm_b_hwdata_i                         ),               
    .rai_hwrite_i                      (rbm_b_hwrite_i                         ),               
    .rai_hrdata_o                      (rbm_b_hrdata_o                         ),               
    .rai_hready_o                      (rbm_b_hready_o                         ),               
    .rai_hresp_o                       (rbm_b_hresp_o                          ),              
    .rai_r2t_intr_o                    (rbm_b_r2t_intr_o                       ),        

    .r2t_clk_w                         (r2t_b_clk_w                            ),                  
    .r2t_rst_n_w                       (r2t_b_rst_n_w                          ),                    
    .en_box                            (r2t_b_en_box                           ),                   
    .write_box                         (r2t_b_write_box                        ),                   
    .r2t_addr_w                        (r2t_b_addr_w                           ),                   
    .r2t_wdat_w                        (r2t_b_wdat_w                           ),                   
    .r2t_rdy_w                         (1'b1                                   ),                  
    .r2t_rdat_w                        (r2t_b_rdat_w                           ),                   
    .r2t_intr_w                        (1'b0                                   )                   
    );

sdpram
   #(
    .ADDR_W                            (ADDR_W                                 )
    )
u_sdpram
    (
    .a_clk_i                           (r2t_a_clk_w                            ),       
    .a_rst_n_i                         (r2t_a_rst_n_w                          ),         
    .a_en_i                            (r2t_a_en_box                           ),      
    .a_write_i                         (r2t_a_write_box                        ),         
    .a_addr_i                          (r2t_a_addr_w                           ),        
    .b_clk_i                           (r2t_b_clk_w                            ),       
    .b_rst_n_i                         (r2t_b_rst_n_w                          ),         
    .b_en_i                            (r2t_b_en_box                           ),      
    .b_addr_i                          (r2t_b_addr_w                           ),        
    .wdat_i                            (r2t_a_wdat_w                           ),      
    .a_rdat_o                          (r2t_a_rdat_w                           ),        
    .b_rdat_o                          (r2t_b_rdat_w                           )
    );
endmodule

